<?php
defined('_JEXEC') or die('Restricted access');

include("components/com_nspro/pChart/pData.class");
include("components/com_nspro/pChart/pChart.class");

$db =& JFactory::getDBO();
$db->setQuery('SELECT COUNT(`id`) FROM `#__nspro_subs`');
$mcount = $db->loadResult();

// For Subscribers
$showpie = false;
$showchart = false;
if ($mcount > 1) {
  $showpie = true;
  $showchart = true;
}


// For Newsletters
$showpie2 = false;
$showchart2 = false;

$db->setQuery('SELECT COUNT(DISTINCT `nid`) FROM `#__nspro_newsletter_openings`');
$mcount = $db->loadResult();

if ($mcount == 1) {
  $showchart2 = true;
}
else if ($mcount > 1) {
  $showpie2 = true;
  $showchart2 = true;
}

// Begin Rendering
?>
<table width="100%" style="border: #ccc 1px solid; background: #f9f9f9;"><tr><td valign="top"><p><h2>NS Pro Statistics</h2></p>
<p>
<table><tr>
<?php

// Sub Pie
if ($showpie) {
  print '<td valign="top"><img src="index.php?option=com_nspro&task=print_sub_conf_pie"/>';
}
else {
  print '<td style="width: 380px;" align="center">' . JText::_('Subscription Pie Not Generated');
}
print '</td><td>';

// Sub Chart
if ($showchart) {
  print '<img src="index.php?option=com_nspro&task=print_sub_statistics&cname=SubChart1&width=700&height=283"/>';
}
else {
  print JText::_('Subscription Chart Not Generated');
}
$juribase = &JURI::base();
print '<br/>';
print '&nbsp;&nbsp;<a class="modal" title="Detailed Subscriber Statistics"'.
      ' href="'.$juribase.'index.php?option=com_nspro&amp;task=sub_stats&amp;tmpl=component"'.
      ' id="subStats" rel="{handler: '."'iframe'".', size: {x: 820, y: 500}}">'.JText::_('See More Detailed Statistics').'</a>';
print '</td></tr></table><br/>';

// Email Pie
print '<table><tr>';
if ($showpie2) {
  print '<td valign="top"><img src="index.php?option=com_nspro&task=print_email_pie"/>';
}
else {
  print '<td style="width: 380px;" align="center">' . JText::_('Email Opening Pie Not Generated');
}
print '</td><td>';
// Email Chart
if ($showchart2) {
  print '<img src="index.php?option=com_nspro&task=print_email_chart&cname=EmailChart1&width=700&height=283"/>';

}
else {
  print JText::_('Email Opening Bar Chart Not Generated') . '</td></tr>'.
        '<tr><td colspan="2"><i>' .
        JText::_('Note: Email Statistics are generated after someone opens one of your newsletters, containing the {img:color} tags.').
        '</i>';
}
$juribase = &JURI::base();
print '<br/>';
print '&nbsp;&nbsp;<a class="modal" title="Detailed Newsletter Statistics"'.
      ' href="'.$juribase.'index.php?option=com_nspro&amp;task=newsletter_stats&amp;tmpl=component"'.
      ' id="newsletterStats" rel="{handler: '."'iframe'".', size: {x: 820, y: 500}}">'.JText::_('See More Detailed Statistics').'</a>';
print '</td></tr></table><br/>';
?>

</p><br/>
<p><small>Please suggest more statistics at the <a href="http://mavrosxristoforos.com/forum">NS Pro Feature Request Forum</a></small></p>
</td></tr></table>